﻿using Microsoft.AspNetCore.Http;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Xman.ActivityId.Http
{
    public class ActivityIdMiddleware
    {
        private readonly RequestDelegate _next;

        public ActivityIdMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            Trace.CorrelationManager.ActivityId = Guid.NewGuid();
            await _next(context);
        }
    }
}
